<template>
  <div class="content" ref="content">
    <div class="table-default" v-if="tableData">
      <el-button type="primary" class="backBtn" @click="backHandler">返回</el-button>
      <!-- <div class="search-hidden" ref="searchbox"> -->
      <div id="base" ref="base">
        <el-descriptions :column="3" border title="基本信息">
          <el-descriptions-item label-class-name="labelClassNAme" class-name="contentClassName" label="单号">{{ tableData.docno }}</el-descriptions-item>
          <el-descriptions-item label-class-name="labelClassNAme" class-name="contentClassName" label="状态">{{ stateList[tableData.status] }}</el-descriptions-item>
          <el-descriptions-item label-class-name="labelClassNAme" class-name="contentClassName" label="创建时间">{{ tableData.created_at }}</el-descriptions-item>
          <!-- <el-descriptions-item label-class-name="labelClassNAme" class-name="contentClassName" label="更新时间">{{ tableData.updated_at }}</el-descriptions-item> -->
        </el-descriptions>
      </div>
      <!-- </div> -->

      <div id="details" ref="details">
        <el-tabs v-model="activeName" class="demo-tabs">
          <el-tab-pane label="调入调出单明细" name="details">
            <el-table :data="detailData" class="mt-3" border>
              <el-table-column prop="material_no" label="品号" min-width="150" />
              <el-table-column prop="from_wms" label="原始仓库" min-width="150" />
              <el-table-column prop="from_location" label="原始库位" min-width="120" />
              <el-table-column prop="from_lotnum" label="原始箱号" min-width="180" />
              <el-table-column prop="to_wms" label="目标仓库" min-width="150" />
              <el-table-column prop="to_location" label="目标库位" min-width="120" />
              <el-table-column prop="to_lotnum" label="目标箱号" min-width="180" />
              <el-table-column prop="qty" label="数量" width="70">
                <template #default="scope">
                  {{ Number(scope.row.qty) }}
                </template>
              </el-table-column>
              <el-table-column prop="unit" label="单位" min-width="80" />
              <el-table-column prop="creator" label="创建者" min-width="170" />
              <el-table-column prop="created_at" label="创建时间" min-width="170" />
              <el-table-column prop="updated_at" label="更新时间" min-width="170" />
            </el-table>
            <Paginate />
          </el-tab-pane>
        </el-tabs>
      </div>
    </div>
  </div>
</template>
  <script lang="ts" setup>
import { computed, onMounted, ref } from 'vue'
import { useGetList } from '/admin/composables/curd/useGetList'
import { useDestroy } from '/admin/composables/curd/useDestroy'
import { useOpen } from '/admin/composables/curd/useOpen'
import { useRouter, useRoute } from 'vue-router'
import http from '/admin/support/http'
import { delDetailRouter } from '/admin/utils/delDetailRouter'

const router = useRouter()
const route = useRoute()

const api = `inventory/transfer/order/${route.query.id}`
const { data, query, search, reset, loading } = useGetList(api)
const { destroy, deleted } = useDestroy()
const { open, close, title, visible, id } = useOpen()

const tableData = computed(() => data.value?.data)

console.log('获取到的tableData：', tableData)

const detailData = ref([])

const getDetail = () => {
  // /aip/production/pick/detail?order_id=领料单id
  const api2 = `inventory/transfer/detail?order_id=${route.query.id}?`
  http.get(api2).then(r => {
    console.log(r.data.data)
    detailData.value = r.data.data
  })
}

getDetail()

const detailAllData = ref([])

const getDetailAll = () => {
  // /aip/production/pick/detail?order_id=领料单id
  const api2 = `production/ware/group/by?ware_id=${route.query.id}`
  http.get(api2).then(r => {
    console.log('请求汇总数据：', r.data.data)
    detailAllData.value = r.data.data
  })
}

getDetailAll()

// const statusFormatter = {
//   0: '待推送',
//   1: '推送成功',
//   2: '推送失败',
// }

let stateList = ref({})
const getState = () => {
  http.get('options/DocStatus').then(r => {
    console.log('单据状态：', r.data.data)
    let res = r.data.data
    res.forEach((item,index) => {
      stateList.value[index] = item.label
    })
  })
}

getState()

const searchbox = ref(null)

// console.log('路由参数接收', route.query.id)

const backHandler = () => {
  delDetailRouter('分步式调拨详情', '/inventory/setby')

}

const activeName = ref('details')
const base = ref(null)
const details = ref(null)
const content = ref()

onMounted(() => {
  search()
  deleted(reset)
})
</script>
  
  <style lang="css">
/* .content{
    border: 2px solid red;
   overflow:hidden;
  } */
.backBtn {
  margin: 20px 10px;
}

h2 {
  font-weight: bold;
}
#base {
  margin-bottom: 30px;
  /* border: 2px solid green; */
}
#details {
  /* border: 2px solid pink; */
}

.tabs {
  padding: 10px 0 0;
  /* border: 2px solid #000; */
  z-index: 999;
  background-color: #fff;
  position: sticky;
  top: -15px;
}

.tagRow {
  display: inline-block;
  /* border: 1px solid #000; */
  margin: 20px 10px;
}

.tagRow ul {
  display: flex;
  border: 1px solid #eee;
}
.tagRow ul li {
  margin: 0 5px;
  /* border: 1px solid #eee; */
  padding: 5px 10px;
  /* border-radius: 5px; */
}
.active {
  background-color: #409eff;
  color: #fff;
}
.labelClassNAme {
  width: 130px;
}
.contentClassName {
  width: 170px;
}
</style>
  